package controller;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;

import model.BoardDAO;

import vo.MemberVO;

public class LoginAction implements Action {
	private static Logger logger = Logger.getLogger(LoginAction.class);
	
	@Override
	public ActionForward execute(HttpServletRequest request, HttpServletResponse response)
			throws ServletException {
		BoardDAO boardDAO = BoardDAO.getInstance();
		MemberVO memberVO = new MemberVO();
		
		String path = "";
		
		String userid = request.getParameter("userid");
		String userpass = request.getParameter("userpass");
		
		memberVO.setUserid(userid);
		memberVO.setUserpass(userpass);
		
		boolean result = boardDAO.loginCheck(memberVO);
		logger.debug("Result: " + result);
		if(result) {
			HttpSession session = request.getSession();
			session.setAttribute("userid", userid);
			request.setAttribute("result", userid + "님 로그인 성공");
			
		} else {
			request.setAttribute("result", userid + "님 로그인 실패");
		}
		path = "/index.jsp";
		return new ActionForward(path, false);
	}
}
